/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1638365704232_8177';

  // add your middleware config here
  config.middleware = ["checktoken"];

  // 检查是否已登录
  config.checktoken = {
    match(ctx) {
      var url = ctx.request.url;
      console.log('config.checktoken', url);
      //
      if (url.indexOf('/login') >= 0 || url.indexOf('/register') >= 0) {
        return false;
      }
      return true;
    }
  }
  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };
  // 配置跨域插件
  config.cors = {
    origin: '*',
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
  };
  config.security = {
    csrf: {
      enable: false
    }
  }
  // 文件上传配置为file模式
  config.multipart = {
    mode: 'stream',
    fileExtensions: ['.jpg', '.png', '.docx', '.pdf', '.doc','.txt'], //扩展几种上传的文件格式
  };
  // 配置jwt插件
  config.jwt = {
    secret: 'thisisasecret'
  };
  // 配置egg-sequelize数据库插件
  config.sequelize = {
    dialect: 'mysql',
    database: 'egg_graduation_project',
    host: '127.0.0.1',
    port: 3306,
    username: 'root',
    password: 'root',
  };
  // 更改端口
  config.cluster = {
    listen: {
      path: '',
      port: 8890,
      hostname: '0.0.0.0'
    }
  }
  config.redis = {
    client: {
      port: 6379,          // Redis port
      host: '127.0.0.1',   // Redis host
      password: '',
      db: 0,
    },
  }
  return {
    ...config,
    ...userConfig,
  };
};
